package niumao.minecraft.uhc.listener;

import niumao.minecraft.uhc.Util;
import org.bukkit.ChatColor;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class bloodlust implements Listener {
    @EventHandler
    public void on(EntityDeathEvent event) {
        if (event.getEntity().getKiller() == null) return;
        Player player = event.getEntity().getKiller();
        if (!(event.getEntity() instanceof Player)) return;
        ItemStack item = player.getInventory().getItemInMainHand();
        ItemMeta itemMeta = item.getItemMeta();
        if (itemMeta == null) return;
        if (itemMeta.getDisplayName().equals(Util.getStr("Bloodlust"))) {
            int i = itemMeta.getCustomModelData();
            itemMeta.setCustomModelData(++i);
            switch (i) {
                case 1:
                    itemMeta.addEnchant(Enchantment.DAMAGE_ALL, 2, true);
                    player.sendMessage("您的武器" + itemMeta.getDisplayName() +
                            ChatColor.GOLD + "升级成功(一阶)");
                    break;
                case 3:
                    itemMeta.addEnchant(Enchantment.DAMAGE_ALL, 3, true);
                    player.sendMessage("您的武器" + itemMeta.getDisplayName() +
                            ChatColor.GOLD + "升级成功(二阶)");
                    break;
                case 6:
                    itemMeta.addEnchant(Enchantment.DAMAGE_ALL, 4, true);
                    player.sendMessage("您的武器" + itemMeta.getDisplayName() +
                            ChatColor.GOLD + "升级成功(三阶)");
                    break;
                case 10:
                    itemMeta.addEnchant(Enchantment.DAMAGE_ALL, 5, true);
                    player.sendMessage("您的武器" + itemMeta.getDisplayName() +
                            ChatColor.GOLD + "升级成功(四阶)");
            }
            item.setItemMeta(itemMeta);
        }
    }
}
